package view;

import controller.MainListener;
import controller.SignInListener;

import javax.swing.*;
import java.awt.*;

public class SignIn extends JDialog{
    //按钮
    JButton button1,button2,button3;
    //中间容器
    JPanel panel1;
    //标签
    JLabel label2,label3,label;
    //用户名文本框
    JTextField tfNum;
    //密码文本框
    JPasswordField tfPwd;
    private SignInListener listener;
    private MainJFrame frame;
    private  JLayeredPane pane;
    private ImageIcon image;

    public SignIn(MainJFrame frame) {
        super();
        this.frame = frame;
        this.setTitle("图书管理系统");


        listener=new SignInListener(this);
        pane = new JLayeredPane();
        panel1 = new JPanel();
        image = new ImageIcon("src/image/photo2.png");
        label2=new JLabel("学 号：");
        label3=new JLabel("密 码：");
        tfNum=new JTextField(15);
        tfPwd=new JPasswordField(15);
        button1 = new JButton(new ImageIcon("src/image/photo1.png"));
        button2 = new JButton(new ImageIcon("src/image/photo3.png"));
        button3 = new JButton(new ImageIcon("src/image/photo4.png"));
        button1.setPressedIcon(new ImageIcon("src/image/photo8.png"));
        button2.setPressedIcon(new ImageIcon("src/image/photo7.png"));
        button3.setPressedIcon(new ImageIcon("src/image/photo6.png"));
        button1.setActionCommand("1");
        button2.setActionCommand("2");
        button3.setActionCommand("3");

        label2.setFont( new Font ( "隶书" , Font.BOLD , 18));
        label3.setFont( new Font ( "隶书" , Font.BOLD , 18));
        button1.setContentAreaFilled(false);//透明
        button1.setBorderPainted(false);//去边框
        button1.setFocusPainted(false);//去焦点
        button2.setContentAreaFilled(false);//透明
        button2.setBorderPainted(false);//去边框
        button2.setFocusPainted(false);//去焦点
        button3.setContentAreaFilled(false);//透明
        button3.setBorderPainted(false);//去边框
        button3.setFocusPainted(false);//去焦点
        button1.addActionListener(listener);
        button2.addActionListener(listener);
        button3.addActionListener(listener);
        //设置透明

        label2.setOpaque(false);
        label3.setOpaque(false);
        tfNum.setOpaque(false);
        tfPwd.setOpaque(false);
//        button3.setOpaque(false);
//        button2.setOpaque(false);
//        button1.setOpaque(false);

        label = new JLabel(image);        //把背景图片添加到标签里
        panel1.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());   //把标签设置为和图片等高等宽
        panel1 = (JPanel) this.getContentPane();    //把我的面板设置为内容面板
        panel1.add(label);


        label2.setBounds(70,130,80,50);
        tfNum.setBounds(140,146,100,20);
        label3.setBounds(70,165,80,50);
        tfPwd.setBounds(140,181,100,20);
        button1.setBounds(60,220,60,40);
        button2.setBounds(132,220,60,40);
        button3.setBounds(202,220,60,40);
        pane.add(panel1, JLayeredPane.DEFAULT_LAYER);

        pane.add(label2, JLayeredPane.MODAL_LAYER);
        pane.add(label3, JLayeredPane.MODAL_LAYER);
        pane.add(tfNum,JLayeredPane.MODAL_LAYER);
        pane.add(tfPwd,JLayeredPane.MODAL_LAYER);
        pane.add(button1,JLayeredPane.MODAL_LAYER);
        pane.add(button2,JLayeredPane.MODAL_LAYER);
        pane.add(button3,JLayeredPane.MODAL_LAYER);


        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLayeredPane(pane);
        this.setVisible(true);
        this.setResizable(false);
        this.setBounds(100, 100, image.getIconWidth(), image.getIconHeight());
        this.setLocationRelativeTo(null);
    }

    public void setButton1(JButton button1) {
        this.button1 = button1;
    }

    public void setTfNum(JTextField tfNum) {
        this.tfNum = tfNum;
    }

    public void setTfPwd(JPasswordField tfPwd) {
        this.tfPwd = tfPwd;
    }

    public JTextField getTfNum() {
        return tfNum;
    }

    public JPasswordField getTfPwd() {
        return tfPwd;
    }

    public MainJFrame getFrame() { return frame; }

    public void setFrame(MainJFrame frame) {
        this.frame = frame;
    }

}